load(
    "//bazel:tachyon_cc.bzl",
    "tachyon_cc_binary",
    "tachyon_cc_library",
    "tachyon_cc_unittest",
    "tachyon_openmp_num_threads_env",
)

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "halo2_hdrs",
    srcs = [
        "bn254_argument_data.h",
        "bn254_instance_columns_vec.h",
        "bn254_prover.h",
        "bn254_transcript.h",
        "bn254_verifier.h",
        "constants.h",
    ],
)

tachyon_cc_library(
    name = "bn254_argument_data",
    srcs = ["bn254_argument_data.cc"],
    hdrs = [
        "bn254_argument_data.h",
        "bn254_argument_data_type_traits.h",
    ],
    deps = [
        "//tachyon/c/base:type_traits_forward",
        "//tachyon/c/math/polynomials:constants",
        "//tachyon/c/math/polynomials/univariate:bn254_univariate_dense_polynomial",
        "//tachyon/c/math/polynomials/univariate:bn254_univariate_evaluations",
        "//tachyon/zk/plonk/halo2:argument_data",
    ],
)

tachyon_cc_library(
    name = "bn254_halo2",
    deps = [
        ":bn254_prover",
        ":bn254_verifier",
    ],
)

tachyon_cc_library(
    name = "bn254_instance_columns_vec",
    srcs = ["bn254_instance_columns_vec.cc"],
    hdrs = [
        "bn254_instance_columns_vec.h",
        "bn254_instance_columns_vec_type_traits.h",
    ],
    deps = [
        "//tachyon/c/base:type_traits_forward",
        "//tachyon/c/math/elliptic_curves/bn/bn254:fr",
    ],
)

tachyon_cc_library(
    name = "bn254_prover",
    srcs = ["bn254_prover.cc"],
    hdrs = ["bn254_prover.h"],
    deps = [
        ":bn254_argument_data",
        ":bn254_ps",
        ":bn254_transcript",
        ":kzg_family_prover_impl",
        "//tachyon/c/base:type_traits_forward",
        "//tachyon/c/math/elliptic_curves/bn/bn254:g1",
        "//tachyon/c/math/elliptic_curves/bn/bn254:g2",
        "//tachyon/c/math/polynomials/univariate:bn254_univariate_evaluation_domain",
        "//tachyon/c/zk/base:bn254_blinder",
        "//tachyon/c/zk/plonk/keys:bn254_plonk_proving_key",
        "//tachyon/crypto/random:rng_type",
        "//tachyon/crypto/random/cha_cha20:cha_cha20_rng",
        "//tachyon/crypto/random/xor_shift:xor_shift_rng",
        "//tachyon/math/elliptic_curves/bn/bn254",
        "//tachyon/math/elliptic_curves/bn/bn254/halo2:bn254",
        "//tachyon/zk/base/commitments:gwc_extension",
        "//tachyon/zk/base/commitments:shplonk_extension",
        "//tachyon/zk/plonk/halo2:pcs_type",
        "//tachyon/zk/plonk/halo2:prover",
        "//tachyon/zk/plonk/halo2:vendor",
    ],
)

tachyon_cc_library(
    name = "bn254_ps",
    hdrs = ["bn254_ps.h"],
    deps = [
        "//tachyon/c/math/polynomials:constants",
        "//tachyon/math/elliptic_curves/bn/bn254",
        "//tachyon/zk/base/commitments:gwc_extension",
        "//tachyon/zk/base/commitments:shplonk_extension",
        "//tachyon/zk/plonk/halo2:proving_scheme",
    ],
)

tachyon_cc_library(
    name = "bn254_transcript",
    srcs = ["bn254_transcript.cc"],
    hdrs = ["bn254_transcript.h"],
    deps = [
        ":constants",
        "//tachyon/base:logging",
        "//tachyon/c:export",
        "//tachyon/c/math/elliptic_curves/bn/bn254:fr",
        "//tachyon/math/elliptic_curves/bn/bn254:g1",
        "//tachyon/zk/plonk/halo2:blake2b_transcript",
        "//tachyon/zk/plonk/halo2:poseidon_transcript",
        "//tachyon/zk/plonk/halo2:sha256_transcript",
        "//tachyon/zk/plonk/halo2:snark_verifier_poseidon_transcript",
        "//tachyon/zk/plonk/halo2:transcript_type",
    ],
)

tachyon_cc_library(
    name = "bn254_verifier",
    srcs = ["bn254_verifier.cc"],
    hdrs = ["bn254_verifier.h"],
    deps = [
        ":bn254_instance_columns_vec",
        ":bn254_ps",
        ":bn254_transcript",
        ":verifier_impl",
        "//tachyon/c/base:type_traits_forward",
        "//tachyon/c/zk/plonk/keys:bn254_plonk_verifying_key",
        "//tachyon/math/elliptic_curves/bn/bn254/halo2:bn254",
        "//tachyon/math/polynomials/univariate:univariate_evaluation_domain_factory",
        "//tachyon/zk/plonk/halo2:pcs_type",
        "//tachyon/zk/plonk/halo2:vendor",
    ],
)

tachyon_cc_library(
    name = "buffer_reader",
    hdrs = ["buffer_reader.h"],
    deps = [
        ":bn254_ps",
        "//tachyon/base:logging",
        "//tachyon/base/buffer:endian_auto_reset",
        "//tachyon/base/buffer:read_only_buffer",
        "//tachyon/base/containers:container_util",
        "//tachyon/math/finite_fields:cubic_extension_field",
        "//tachyon/math/finite_fields:prime_field_base",
        "//tachyon/math/finite_fields:quadratic_extension_field",
        "//tachyon/math/geometry:affine_point",
        "//tachyon/math/polynomials/univariate:univariate_evaluations",
        "//tachyon/math/polynomials/univariate:univariate_polynomial",
        "//tachyon/zk/expressions:expression_factory",
        "//tachyon/zk/lookup:argument",
        "//tachyon/zk/plonk/base:column_key",
        "//tachyon/zk/plonk/base:phase",
        "//tachyon/zk/plonk/constraint_system:challenge",
        "//tachyon/zk/plonk/constraint_system:gate",
        "//tachyon/zk/plonk/constraint_system:lookup_tracker",
        "//tachyon/zk/plonk/constraint_system:query",
        "//tachyon/zk/plonk/expressions:expression_factory",
        "//tachyon/zk/plonk/permutation:permutation_argument",
        "//tachyon/zk/shuffle:argument",
        "@com_google_absl//absl/container:btree",
    ],
)

tachyon_cc_library(
    name = "constants",
    hdrs = ["constants.h"],
)

tachyon_cc_library(
    name = "halo2",
    deps = [":bn254_halo2"],
)

tachyon_cc_library(
    name = "kzg_family_prover_impl",
    hdrs = ["kzg_family_prover_impl.h"],
    deps = [
        ":prover_impl_base",
        "//tachyon/base:logging",
        "//tachyon/c/base:type_traits_forward",
        "//tachyon/c/math/elliptic_curves:point_traits_forward",
        "//tachyon/math/elliptic_curves/msm:variable_base_msm",
        "@com_google_absl//absl/types:span",
    ],
)

tachyon_cc_library(
    name = "prover_impl_base",
    hdrs = ["prover_impl_base.h"],
    deps = [
        "//tachyon/base:environment",
        "//tachyon/base:logging",
        "//tachyon/base/files:file_util",
        "//tachyon/base/functional:callback",
        "//tachyon/zk/plonk/halo2:proof_serializer",
        "//tachyon/zk/plonk/halo2:prover",
    ],
)

tachyon_cc_binary(
    name = "prover_replay",
    srcs = ["prover_replay.cc"],
    deps = [
        ":bn254_prover",
        "//tachyon/base:logging",
        "//tachyon/base/console",
        "//tachyon/base/files:file_path_flag",
        "//tachyon/base/files:file_util",
        "//tachyon/base/flag:flag_parser",
        "//tachyon/c/math/elliptic_curves/bn/bn254:fr",
        "//tachyon/c/zk/plonk/keys:proving_key_impl",
        "//tachyon/crypto/random:rng_type",
        "//tachyon/crypto/random/cha_cha20:cha_cha20_rng",
        "//tachyon/crypto/random/xor_shift:xor_shift_rng",
        "//tachyon/zk/plonk/halo2:constants",
        "//tachyon/zk/plonk/halo2:pcs_type",
        "//tachyon/zk/plonk/halo2:transcript_type",
        "//tachyon/zk/plonk/halo2:vendor",
    ],
)

tachyon_cc_library(
    name = "prover_traits_forward",
    hdrs = ["prover_traits_forward.h"],
)

tachyon_cc_library(
    name = "verifier_impl",
    hdrs = ["verifier_impl.h"],
    deps = [
        "//tachyon/base/containers:container_util",
        "//tachyon/base/functional:callback",
        "//tachyon/zk/plonk/halo2:verifier",
    ],
)

tachyon_cc_binary(
    name = "verifier_replay",
    srcs = ["verifier_replay.cc"],
    deps = [
        ":bn254_verifier",
        "//tachyon/base:logging",
        "//tachyon/base/console",
        "//tachyon/base/files:file_path_flag",
        "//tachyon/base/files:file_util",
        "//tachyon/base/flag:flag_parser",
        "//tachyon/c/math/elliptic_curves/bn/bn254:fr",
        "//tachyon/c/zk/plonk/keys:proving_key_impl",
        "//tachyon/zk/plonk/halo2:transcript_type",
    ],
)

tachyon_cc_unittest(
    name = "halo2_unittests",
    # NOTE(chokobole): Timeout time increased due to CI.
    timeout = "moderate",
    srcs = [
        "bn254_prover_unittest.cc",
        "bn254_transcript_unittest.cc",
    ],
    env = tachyon_openmp_num_threads_env(4),
    deps = [
        ":bn254_prover",
        "//tachyon/c/crypto/random:rng",
        "//tachyon/c/zk/plonk/halo2/test:bn254_halo2_params_data",
        "//tachyon/cc/math/elliptic_curves/bn/bn254:fr",
        "//tachyon/math/finite_fields/test:finite_field_test",
        "//tachyon/zk/lookup/halo2:scheme",
    ],
)
